﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FastMvc.Crud
{
    /// <summary>
    /// 所有数据库表的基类
    /// </summary>
    public class DBEntity<TPrimaryKey>
    {
        /// <summary>
        /// 唯一主键，当前系统，全部采用Guid作为唯一主键
        /// </summary>
        public virtual TPrimaryKey sId { get; set; }

        public int iDelete { get; set; } = 0;

        private DateTime _creatTime = DateTime.MinValue;
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime dCreateTime
        {
            get
            {
                if (_creatTime == DateTime.MinValue)
                    return DateTime.Now;
                return _creatTime;
            }
            set { _creatTime = value; }
        }

        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime dUpdateTime { get; set; } = DateTime.Now;
    }

    /// <summary>
    /// 所有数据库类的基类（默认采用Guid格式的字符串为主键）
    /// </summary>
    public class DBEntity : DBEntity<string>
    {
        public override string sId { get; set; } = Guid.NewGuid().ToString();
    }
}
